<?php
	session_start();
	$data=$_SESSION["user_object"];
	
	?>
<!DOCTYPE html>
<html class="ui-page-login">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>邮箱激活页面</title>
		<link href="css/mui.min.css" rel="stylesheet" />
        <link href="css/library.css"  rel="stylesheet"/>
        <script src="js/mui.min.js"></script>
        <script type="text/javascript" src="js/jquery-2.1.0.js" ></script>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">邮箱激活</h1>
		</header>
		<div class="mui-content">
			
			<div class="loginTop">
				<img class="loginTopLogo" src="img/icon.jpg" />
			</div>
			<div class="mui-content-padded">
			<form id='login-form' method="post" action="sendmail.php" class="mui-input-group input-form">
				<div class="mui-input-row">
					<label>读者账号</label>
					<input id='account' disabled="disabled" value="<?php echo $data["username"];?>" name="username" type="text" class="mui-input-clear mui-input" placeholder="读者账号" required="required" oninvalid="">
				</div>
				<div class="mui-input-row">
					<label>绑定邮箱</label>
					<input id='tomail' value="<?php echo $data["email"];?>" name="toemail" type="text" class="mui-input-clear mui-input" placeholder="验证邮箱" required="required">
				</div>
			</form>
				<button id="activated_btn" class="mui-btn-primary mui-btn-exclusive submit-btn" >马上激活</button>
			</div>
		</div>
		<script>
			//		发送验证连接的BTN
	var getConfirmNum = document.getElementById("activated_btn");
	var num = 10;
	getConfirmNum.addEventListener('click', ajaxEmail)
	var tomail=document.getElementById("tomail");
	
    function ajaxEmail(){
    	test();
    	alert(tomail.value);
    	$.ajax({
		type:"post",
		url:"sendmail.php",
		data:{
			"toemail":tomail.value,
			"user_id":<?php echo $data["id"];?>
		},
		async:true,
		success:function(data){
			if(data==1){
				alert("激活邮件已经发送");
				//username.setCustomValidity("用户名已经存在");
			}else{
				
			}
		}
	});
    }
	function test() {
		getConfirmNum.value = num;
		num -= 1;
		i = setTimeout("test()", 1000);
		if (num == 0) {
			clearTimeout(i);
			getConfirmNum.disabled = false;
			getConfirmNum.className = "mui-btn-primary mui-btn-exclusive submit-btn";
			
			getConfirmNum.innerHTML = "获取验证码";
			num = 10;
		} else {
			getConfirmNum.className = "mui-btn-danger mui-btn-exclusive submit-btn";
			getConfirmNum.innerHTML = num + "秒后重发";
			getConfirmNum.disabled = true;
		}
	}
	
		</script>
	</body>

